<?php
  require_once('db_connection.php');

  print_r($_GET);
  // if set in URL then update

  if(isset($_GET['status']) && isset($_GET['id'])) {
    $url_status = ($_GET['status'] == 1) ? 0 : 1;
    $url_id = $_GET['id'];
    $update_query = "UPDATE `users` SET `status`='$url_status'
                                    WHERE `id`= '$url_id' ";
    mysql_query($update_query) or die(mysql_error());
    if(mysql_affected_rows()==1){
      echo "<h4>Status changed successfully..</h4>";
    }
  }

  $query = "SELECT * FROM `users`";
  $result  = mysql_query($query) or die(mysql_error());

  $selected_records = mysql_num_rows($result);
  echo "<h4>TOTAL : $selected_records </h4>";

?>

<link href="../html/css/site.css" rel="stylesheet" type="text/css" />

<table width="80%" cellspacing="0" cellpadding="0">
  <thead>
    <tr>
      <th>ID</th>
      <th>NAME</th>
      <th>EMAIL</th>
      <th>ADDED DATE</th>
      <th>STATUS</th>
    </tr>
  </thead>
  <tbody>
<?php
  while($ans = mysql_fetch_assoc($result)){
    $status = getStatus($ans['status']);
    $url = "?id=$ans[id]&status=$ans[status]";
    $status = '<a href="'.$url.'">'.$status.'</a>';
?>
    <tr>
      <td><?=$ans['id']?></td>
      <td><?=$ans['name']?></td>
      <td><a href="mailto:<?=$ans['email']?>"><?=$ans['email']?></a></td>
      <td><?=date('d-M-Y h:i:s a',strtotime($ans['added_date']))?></td>
      <td><?=$status?></td>
    </tr>
<?php
    //print_r($ans);
  }
?>


  </tbody>
</table>

